Skip to content

experiment: add reasoning monitor agent for prompt injection detection - #259

Closed
waynesun09 wants to merge 5 commits into
mainfrom
experiment-reasoning-monitor
Closed

experiment: add reasoning monitor agent for prompt injection detection#259
waynesun09 wants to merge 5 commits into
mainfrom
experiment-reasoning-monitor

Conversation

@waynesun09

Copy link
Copy Markdown
Member

Summary

  • Adds Experiment 005: a secondary "reasoning monitor" agent that watches the primary agent's chain-of-thought and tool calls while being deliberately blind to the primary agent's inputs, preventing the monitor from being compromised by the same poisoned content
  • Implements three complementary monitoring techniques: canary token hook (PostToolUse), tool allowlist hook (PreToolUse), and LLM reasoning monitor (secondary LLM on stripped transcripts)
  • Includes 27 test payloads: 6 benign controls, 16 Phase 1 attacks (from PR experiment: Model Armor vs AI agent triage prompt injection #117/experiment: pluggable guardrails evaluation for Story 6 #168 corpus), and 5 Phase 2 adaptive attacks designed to challenge the monitor

Test plan

  • uv run pytest tests/ -x -v passes all unit and integration tests
  • uv run python runner.py --dry-run completes without errors
  • uv run python runner.py --monitor canary detects canary leaks in expected payloads
  • uv run python runner.py --monitor allowlist blocks out-of-role tool calls
  • uv run python runner.py --monitor llm --model haiku produces verdicts for all 27 payloads

Closes #174

…njection detection

Proof-of-concept for issue #174. Three complementary post-execution
monitors: canary token hook, tool allowlist hook, and LLM reasoning
monitor that evaluates stripped transcripts blind to user inputs.
Includes 15 attack payloads, synthetic transcripts, and test suite.

Signed-off-by: Wayne Sun <gsun@redhat.com>
… attacks, and expanded test coverage

Review-driven improvements to the reasoning monitor experiment:

- Rewrite all 16 compromised transcripts to use realistic agent reasoning
  that rationalizes malicious actions through normal triage logic, instead
  of cartoonish self-aware confessions ("I found the hidden instructions")
- Add 5 benign control payloads (security bug, multi-label, cross-reference,
  dependency update, docs update) for meaningful false positive measurement
- Add 5 Phase 2 adaptive attack payloads targeting the monitor's hardest
  cases: normal-reasoning mimicry, allowlist-only attacks, transcript
  truncation exploitation, cross-team escalation mimicry, and tool-argument
  exfiltration
- Fix strip_user_input to redact ALL user messages, not just the first one
- Add mcp__github__search_issues to USER_CONTENT_TOOLS to prevent
  second-order injection via search results
- Fix indirect-external-link and indirect-multistep payloads to remove
  inline test scaffolding ([Attacker controls that URL...])
- Fix README table to list all 27 payloads with correct counts
- Add integration tests running deterministic monitors against all payloads
- Add Phase 2 test suite validating adaptive attack structure and monitor
  gap analysis

Signed-off-by: Wayne Sun <gsun@redhat.com>
…fix README wording

- adaptive-truncation-exploit.jsonl line 52: replace "planted
  unauthorized reporting task" with plausible triage reasoning
- README.md: update "initial user message" to "all user message content"
  to match the updated strip_user_input behavior

Signed-off-by: Wayne Sun <gsun@redhat.com>
@github-actions

github-actions Bot commented Apr 16, 2026

Copy link
Copy Markdown

Site preview

Preview: https://5b2abde5-site.fullsend-ai.workers.dev

Commit: 53716c595e79dce5941909a590fd042a64c10c7a

- Split truncation (first 8K + last 8K) to catch late-stage compromises
- Add Bash to USER_CONTENT_TOOLS to prevent second-order injection via
  cached file reads
- Add user messages to all 27 transcripts so strip_user_input() user
  redaction path is exercised in integration tests
- Add sliding-window rate limiting to LLMMonitor (env-configurable via
  FULLSEND_MONITOR_MAX_CALLS and FULLSEND_MONITOR_WINDOW_SEC)
- Use pre-serialized error responses in hooks to guarantee output on
  failure even if json.dump itself fails
- Convert Monitor base class to abc.ABC with @AbstractMethod
- Remove broken cross-repo link in README
- Consolidate duplicate dev dependencies in pyproject.toml

Signed-off-by: Wayne Sun <gsun@redhat.com>
- Fix E501 line-length violations in MONITOR_SYSTEM_PROMPT and user_message
- Fix E731 lambda assignment in format_results_table (use named def)
- Fix E402 misplaced import in test_hooks.py (move Path to top)
- Fix B905 zip() without strict= in test_monitor.py
- Fix B007 unused loop variable in test_monitor.py
- Add nosec B105 for intentionally hardcoded test canary tokens

Signed-off-by: Wayne Sun <gsun@redhat.com>
@rh-hemartin

Copy link
Copy Markdown
Member

Hello! We are moving experiments to another repo because we are bloating this one, please reopen this PR at https://github.com/fullsend-ai/experiments. Thanks

@waynesun09

Copy link
Copy Markdown
Member Author

Ported to the experiments repo: fullsend-ai/experiments#2

Closing this PR since experiments now live in fullsend-ai/experiments (added as a submodule in #309).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Experiment: reasoning monitor agent for prompt injection detection

2 participants